/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.asu.cse360.service.impl;

import edu.asu.cse360.annotation.TargetEntity;
import edu.asu.cse360.dao.DataAccessObject;
import edu.asu.cse360.model.ItemOrder;
import edu.asu.cse360.model.MenuItem;
import edu.asu.cse360.model.Restaurant;
import edu.asu.cse360.service.ItemOrderService;
import edu.asu.cse360.service.MenuItemService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("menuItemService")
public class MenuItemServiceImpl implements MenuItemService{

    @Autowired
    @TargetEntity(MenuItem.class)
    private DataAccessObject<MenuItem, Integer> menuItemDao;


    @Override
    public List<MenuItem> getAvailableMenuItems(Restaurant res) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("restaurant", res);
        return menuItemDao.findList(MenuItem.FIND_AVAILABLE_BY_RESTAURANT, params);
    }

    @Override
    public MenuItem save(MenuItem menuItem) {
        if(menuItem.getId() == null){
            menuItemDao.create(menuItem);
        }else{
            menuItemDao.update(menuItem);
        }
        return menuItem;
    }

    @Override
    public MenuItem remove(MenuItem menuItem) {
        menuItem.setAvailable(false);
        this.save(menuItem);
        return menuItem;
    }

}
